
USE [CamelioDB]
GO

/****** Object:  StoredProcedure [proc_AdminLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_AdminLoadByPrimaryKey]
(
	@AdminID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[AdminID],
		[AminUserName],
		[AdminPassword],
		[AdminType]
	FROM [Admin]
	WHERE
		([AdminID] = @AdminID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminLoadAll];
GO

CREATE PROCEDURE [proc_AdminLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[AdminID],
		[AminUserName],
		[AdminPassword],
		[AdminType]
	FROM [Admin]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminUpdate];
GO

CREATE PROCEDURE [proc_AdminUpdate]
(
	@AdminID int,
	@AminUserName nvarchar(250) = NULL,
	@AdminPassword nvarchar(50) = NULL,
	@AdminType nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Admin]
	SET
		[AminUserName] = @AminUserName,
		[AdminPassword] = @AdminPassword,
		[AdminType] = @AdminType
	WHERE
		[AdminID] = @AdminID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_AdminInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminInsert];
GO

CREATE PROCEDURE [proc_AdminInsert]
(
	@AdminID int = NULL output,
	@AminUserName nvarchar(250) = NULL,
	@AdminPassword nvarchar(50) = NULL,
	@AdminType nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Admin]
	(
		[AminUserName],
		[AdminPassword],
		[AdminType]
	)
	VALUES
	(
		@AminUserName,
		@AdminPassword,
		@AdminType
	)

	SET @Err = @@Error

	SELECT @AdminID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminDelete];
GO

CREATE PROCEDURE [proc_AdminDelete]
(
	@AdminID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Admin]
	WHERE
		[AdminID] = @AdminID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CategoriesLoadByPrimaryKey]
(
	@CatID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CatID],
		[CatName]
	FROM [Categories]
	WHERE
		([CatID] = @CatID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesLoadAll];
GO

CREATE PROCEDURE [proc_CategoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[CatID],
		[CatName]
	FROM [Categories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesUpdate];
GO

CREATE PROCEDURE [proc_CategoriesUpdate]
(
	@CatID int,
	@CatName nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Categories]
	SET
		[CatName] = @CatName
	WHERE
		[CatID] = @CatID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CategoriesInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesInsert];
GO

CREATE PROCEDURE [proc_CategoriesInsert]
(
	@CatID int = NULL output,
	@CatName nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Categories]
	(
		[CatName]
	)
	VALUES
	(
		@CatName
	)

	SET @Err = @@Error

	SELECT @CatID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesDelete];
GO

CREATE PROCEDURE [proc_CategoriesDelete]
(
	@CatID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Categories]
	WHERE
		[CatID] = @CatID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_DailySalesLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_DailySalesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_DailySalesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_DailySalesLoadByPrimaryKey]
(
	@DailySaleID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[DailySaleID],
		[DailySaleDesc],
		[DailySalePaid],
		[DailySaleDate],
		[DailySaleTime]
	FROM [DailySales]
	WHERE
		([DailySaleID] = @DailySaleID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_DailySalesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_DailySalesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_DailySalesLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_DailySalesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_DailySalesLoadAll];
GO

CREATE PROCEDURE [proc_DailySalesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[DailySaleID],
		[DailySaleDesc],
		[DailySalePaid],
		[DailySaleDate],
		[DailySaleTime]
	FROM [DailySales]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_DailySalesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_DailySalesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_DailySalesUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_DailySalesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_DailySalesUpdate];
GO

CREATE PROCEDURE [proc_DailySalesUpdate]
(
	@DailySaleID int,
	@DailySaleDesc nvarchar(250) = NULL,
	@DailySalePaid float = NULL,
	@DailySaleDate nvarchar(50) = NULL,
	@DailySaleTime nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [DailySales]
	SET
		[DailySaleDesc] = @DailySaleDesc,
		[DailySalePaid] = @DailySalePaid,
		[DailySaleDate] = @DailySaleDate,
		[DailySaleTime] = @DailySaleTime
	WHERE
		[DailySaleID] = @DailySaleID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_DailySalesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_DailySalesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_DailySalesInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_DailySalesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_DailySalesInsert];
GO

CREATE PROCEDURE [proc_DailySalesInsert]
(
	@DailySaleID int = NULL output,
	@DailySaleDesc nvarchar(250) = NULL,
	@DailySalePaid float = NULL,
	@DailySaleDate nvarchar(50) = NULL,
	@DailySaleTime nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [DailySales]
	(
		[DailySaleDesc],
		[DailySalePaid],
		[DailySaleDate],
		[DailySaleTime]
	)
	VALUES
	(
		@DailySaleDesc,
		@DailySalePaid,
		@DailySaleDate,
		@DailySaleTime
	)

	SET @Err = @@Error

	SELECT @DailySaleID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_DailySalesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_DailySalesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_DailySalesDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_DailySalesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_DailySalesDelete];
GO

CREATE PROCEDURE [proc_DailySalesDelete]
(
	@DailySaleID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [DailySales]
	WHERE
		[DailySaleID] = @DailySaleID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_DailySalesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_DailySalesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductsLoadByPrimaryKey]
(
	@ProdID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ProdID],
		[CatID],
		[ProdName],
		[ProdType],
		[ProdIsSoiree],
		[ProdColor],
		[ProdSize],
		[ProdQuantity],
		[ProdNetPrice],
		[ProdPrice]
	FROM [Products]
	WHERE
		([ProdID] = @ProdID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsLoadAll];
GO

CREATE PROCEDURE [proc_ProductsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ProdID],
		[CatID],
		[ProdName],
		[ProdType],
		[ProdIsSoiree],
		[ProdColor],
		[ProdSize],
		[ProdQuantity],
		[ProdNetPrice],
		[ProdPrice]
	FROM [Products]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsUpdate];
GO

CREATE PROCEDURE [proc_ProductsUpdate]
(
	@ProdID int,
	@CatID int = NULL,
	@ProdName nvarchar(250) = NULL,
	@ProdType nvarchar(50) = NULL,
	@ProdIsSoiree bit = NULL,
	@ProdColor nvarchar(50) = NULL,
	@ProdSize nvarchar(50) = NULL,
	@ProdQuantity int = NULL,
	@ProdNetPrice float = NULL,
	@ProdPrice float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Products]
	SET
		[CatID] = @CatID,
		[ProdName] = @ProdName,
		[ProdType] = @ProdType,
		[ProdIsSoiree] = @ProdIsSoiree,
		[ProdColor] = @ProdColor,
		[ProdSize] = @ProdSize,
		[ProdQuantity] = @ProdQuantity,
		[ProdNetPrice] = @ProdNetPrice,
		[ProdPrice] = @ProdPrice
	WHERE
		[ProdID] = @ProdID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductsInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsInsert];
GO

CREATE PROCEDURE [proc_ProductsInsert]
(
	@ProdID int,
	@CatID int = NULL,
	@ProdName nvarchar(250) = NULL,
	@ProdType nvarchar(50) = NULL,
	@ProdIsSoiree bit = NULL,
	@ProdColor nvarchar(50) = NULL,
	@ProdSize nvarchar(50) = NULL,
	@ProdQuantity int = NULL,
	@ProdNetPrice float = NULL,
	@ProdPrice float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Products]
	(
		[ProdID],
		[CatID],
		[ProdName],
		[ProdType],
		[ProdIsSoiree],
		[ProdColor],
		[ProdSize],
		[ProdQuantity],
		[ProdNetPrice],
		[ProdPrice]
	)
	VALUES
	(
		@ProdID,
		@CatID,
		@ProdName,
		@ProdType,
		@ProdIsSoiree,
		@ProdColor,
		@ProdSize,
		@ProdQuantity,
		@ProdNetPrice,
		@ProdPrice
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsDelete];
GO

CREATE PROCEDURE [proc_ProductsDelete]
(
	@ProdID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Products]
	WHERE
		[ProdID] = @ProdID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SalesLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SalesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SalesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SalesLoadByPrimaryKey]
(
	@SaleID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SaleID],
		[ProdID],
		[SaledPrice],
		[SaleDate],
		[SaleTime],
		[SaleQuantity]
	FROM [Sales]
	WHERE
		([SaleID] = @SaleID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SalesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SalesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SalesLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SalesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SalesLoadAll];
GO

CREATE PROCEDURE [proc_SalesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SaleID],
		[ProdID],
		[SaledPrice],
		[SaleDate],
		[SaleTime],
		[SaleQuantity]
	FROM [Sales]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SalesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SalesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SalesUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SalesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SalesUpdate];
GO

CREATE PROCEDURE [proc_SalesUpdate]
(
	@SaleID int,
	@ProdID int = NULL,
	@SaledPrice float = NULL,
	@SaleDate nvarchar(50) = NULL,
	@SaleTime nvarchar(50) = NULL,
	@SaleQuantity int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Sales]
	SET
		[ProdID] = @ProdID,
		[SaledPrice] = @SaledPrice,
		[SaleDate] = @SaleDate,
		[SaleTime] = @SaleTime,
		[SaleQuantity] = @SaleQuantity
	WHERE
		[SaleID] = @SaleID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SalesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SalesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SalesInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SalesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SalesInsert];
GO

CREATE PROCEDURE [proc_SalesInsert]
(
	@SaleID int = NULL output,
	@ProdID int = NULL,
	@SaledPrice float = NULL,
	@SaleDate nvarchar(50) = NULL,
	@SaleTime nvarchar(50) = NULL,
	@SaleQuantity int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Sales]
	(
		[ProdID],
		[SaledPrice],
		[SaleDate],
		[SaleTime],
		[SaleQuantity]
	)
	VALUES
	(
		@ProdID,
		@SaledPrice,
		@SaleDate,
		@SaleTime,
		@SaleQuantity
	)

	SET @Err = @@Error

	SELECT @SaleID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SalesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SalesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SalesDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SalesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SalesDelete];
GO

CREATE PROCEDURE [proc_SalesDelete]
(
	@SaleID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Sales]
	WHERE
		[SaleID] = @SaleID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SalesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SalesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SuppliersLoadByPrimaryKey]
(
	@SupplierID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SupplierID],
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	FROM [Suppliers]
	WHERE
		([SupplierID] = @SupplierID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadAll];
GO

CREATE PROCEDURE [proc_SuppliersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SupplierID],
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	FROM [Suppliers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersUpdate];
GO

CREATE PROCEDURE [proc_SuppliersUpdate]
(
	@SupplierID int,
	@SupplierName nvarchar(50) = NULL,
	@SupplierPhone nvarchar(50) = NULL,
	@SupplierTotalBalance float = NULL,
	@SupplierPaidBalance float = NULL,
	@SupplierRemainBalance float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Suppliers]
	SET
		[SupplierName] = @SupplierName,
		[SupplierPhone] = @SupplierPhone,
		[SupplierTotalBalance] = @SupplierTotalBalance,
		[SupplierPaidBalance] = @SupplierPaidBalance,
		[SupplierRemainBalance] = @SupplierRemainBalance
	WHERE
		[SupplierID] = @SupplierID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SuppliersInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersInsert];
GO

CREATE PROCEDURE [proc_SuppliersInsert]
(
	@SupplierID int = NULL output,
	@SupplierName nvarchar(50) = NULL,
	@SupplierPhone nvarchar(50) = NULL,
	@SupplierTotalBalance float = NULL,
	@SupplierPaidBalance float = NULL,
	@SupplierRemainBalance float = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Suppliers]
	(
		[SupplierName],
		[SupplierPhone],
		[SupplierTotalBalance],
		[SupplierPaidBalance],
		[SupplierRemainBalance]
	)
	VALUES
	(
		@SupplierName,
		@SupplierPhone,
		@SupplierTotalBalance,
		@SupplierPaidBalance,
		@SupplierRemainBalance
	)

	SET @Err = @@Error

	SELECT @SupplierID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersDelete];
GO

CREATE PROCEDURE [proc_SuppliersDelete]
(
	@SupplierID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Suppliers]
	WHERE
		[SupplierID] = @SupplierID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersDelete Error on Creation'
GO
